package com.bigdata.controller;

import com.bigdata.entity.pojo.Result;
import com.bigdata.entity.NWQualityRankVO;
import com.bigdata.service.NWQualityRankService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/network")
@RequiredArgsConstructor
public class NWQualityRankController {

    private final NWQualityRankService nwQualityRankService;

    @GetMapping("/rank")
    public Result<NWQualityRankVO> getNetworkQualityRank(
            @RequestParam(value = "startTime", required = false, defaultValue = "0") Long startTime,
            @RequestParam(value = "endTime", required = false, defaultValue = "0") Long endTime,
            @RequestParam(value = "networkQuality", defaultValue = "下行速率") String networkQuality) {

        try {
            log.info("获取网络质量排名数据, networkQuality={}", networkQuality);
            NWQualityRankVO data = nwQualityRankService.getNetworkQualityRank(startTime, endTime, networkQuality);
            return Result.success(data);
        } catch (Exception e) {
            log.error("获取网络质量排名数据失败", e);
            return Result.error("获取网络质量排名数据失败");
        }
    }
}